package com.beimi.game.cmd;

import com.beimi.game.BaseGame;
import com.beimi.game.MJService;
import com.beimi.game.module.GamePlayerModule;
import com.beimi.game.module.GameTurnModule;
import com.beimi.game.player.GamePlayer;
import com.beimi.net.AbstractGameCmd;
import com.next.core.util.GenericAnnotation;
import com.next.core.util.StatMap;

@GenericAnnotation(type = "gang")
public class CmdGang extends AbstractGameCmd {
	@Override
	public void execute(MJService service, GamePlayer player, String data) {
		BaseGame game = service.getGame();
		// var seatIndex = seatData.seatIndex;
		// var game = seatData.game;
		int pai = Integer.parseInt(data);

		// 如果没有杠的机会，则不能再杠
		if (!player.getCardModule().isCanGang()) {
			LOG.warn("seatData.gang == false");
			return;
		}

		StatMap<Integer> countMap = player.getCardModule().getCountMap();
		int numOfCnt = countMap.get(pai);

		// 胡了的，只能直杠
		if (numOfCnt != 1 && player.getCardModule().isHued()) {
			LOG.warn("you have already hued. no kidding plz.");
			return;
		}

		// //如果有人可以胡牌，则需要等待
		for (int i = 0; i < 3; i++) {
			int tmp = game.getModule(GameTurnModule.class).getCurrentTurn() + i;
			GamePlayer player2 = game.getModule(GamePlayerModule.class).getPlayers()[tmp];
			if (player2 != null && player2.isCanChuPai()) {
				return;
			}
		}

		String gangType = "";
		if(numOfCnt == 1){
			gangType = "wangang";
		 }
		else if(numOfCnt == 3) {
			gangType = "diangang";
		}
		else if(numOfCnt == 4) {
			gangType = "angang";
		}
		else {
			return;
		}
		
		
		// game.chuPai = -1;
		// clearAllOptions(game);
		// seatData.canChuPai = false;
		//
		// userMgr.broacastInRoom('hangang_notify_push',seatIndex,seatData.userId,true);
		//
		// //如果是弯杠，则需要检查是否可以抢杠
		// var turnSeat = game.gameSeats[game.turn];
		// if(numOfCnt == 1){
		// var canQiangGang = checkCanQiangGang(game,turnSeat,seatData,pai);
		// if(canQiangGang){
		// return;
		// }
		// }
		//
		// doGang(game,turnSeat,seatData,gangtype,numOfCnt,pai);
	}
}
